<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%      response.setHeader("Cache-Control", "no-cache"); //HTTP 1.1
        response.setHeader("Pragma", "no-cache"); //HTTP 1.0
        response.setDateHeader("Expires", 0); //prevent caching at the proxy server
        session.setAttribute("token", java.util.UUID.randomUUID().toString());

%>

<c:catch var ="catchException"></c:catch>
<sql:query var="query" dataSource="jdbc/dbo_MicrosoftSQLServer">
    select id_usuario, nome_usuario, id_perfil  from Usuarios
    where login_usuario=?
    and  PWDCOMPARE(?,senha_usuario, 0)=?
    <sql:param value="${param.login}"/>
    <sql:param value="${param.senha}"/>
    <sql:param value="1"/>
</sql:query>
<c:forEach var="row" items="${query.rows}">
    <c:set var="id_usuario" value="${row.id_usuario}" scope="session"/>
    <c:set var="id_perfil" value="${row.id_perfil}" scope="session"/>
    <c:set var="nome_usuario" value="${row.nome_usuario}" scope="session"/>
</c:forEach>
<c:if test="${!empty query.rows}">
    <script>
        window.location='index.jsp'
    </script>
</c:if>

<c:if test="${empty query.rows}">
    Login inválido
</c:if>    
